﻿import com.dinmax.isolution.*

class LightDimmerGUI
extends MovieClip {
	
	private var device:LightDimmer;
	private var listener:WindowDeviceGUI;
	
	function LightDimmerGUI(){
		if(this._parent._parent instanceof WindowDeviceGUI)	this.listener = WindowDeviceGUI(this._parent._parent);
		return;
	}
		
	public function getDevice():LightDimmer{
		return this.device;
	}
	public function setDevice(newDevice:LightDimmer):Void{
		this.device = newDevice;
		this.refresh();
		return;
	}
	
	public function setSelected(b:Boolean):Void {
		
		if(b){
			this.gotoAndStop(2);
			this.listener.showDeviceView(this.device);			
			
		} else {
			this.gotoAndStop(1);
			
		}
		return;
	}
	
	public function getSelected():Boolean{
		return (this._currentframe == 2);
	}
	
	public function refresh():Void {
		
		this["txt_title"].text = this.device.getName();
		this["txt_group"].text = this.device.getGroup();
		var val:Number = this.device.getValue();
		(val > 0) ? this["mcState"].gotoAndStop(1) : this["mcState"].gotoAndStop(2);
		this["txt_value"].text = Math.round(val)+"%";
		this["mcValue"].mcLuz.gotoAndStop(Math.floor(val/10+1));	
		 
		return;
	}
	
}